package com.tz.springmvc.framework.converter;

import org.springframework.core.convert.converter.Converter;

import com.tz.springmvc.sysmanage.entity.User;

/**
 * 这个类型转换器就是专门为了将1-2-3-4这种格式转化为User对象
 * @author Administrator
 *
 */
public class SpecialFormatterConvert implements Converter<String,User>{
	@Override
	public User convert(String source) {
		User user = new User();
		if(source!=null){
			String[] userString = source.split("-");
			if(userString!=null&&userString.length>0){
				//userName-loginName-sex-age 
				String userName= userString[0];
				String loginName= userString[1];
				String sex= userString[2];
				String age= userString[3];
				user.setUserName(userName);
				user.setLoginName(loginName);
				user.setSex(new Integer(sex));
				user.setAge(new Integer(age));
			}
		}
		
		
		return user;
	}

}
